<template>
    <div>
        <h1>等级添加页面</h1>
        <table>
            <thead>
                <tr>
                    <td>等级名称</td>
                    <td>
                        <input type="text" v-model="data.Dname">
                    </td>
                </tr>
                <tr>
                    <td>等级权益</td>
                    <td>
                        <input type="text" v-model="data.QuanYi">
                    </td>
                </tr>
                <tr>
                    <td>等级权益外键</td>
                    <td>
                        <select v-model="data.QYwj">
                            <option value="0">请选择</option>
                            <option v-for="a in xlk" :value="a.QYId">{{a.QYName}}</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td>等级状态</td>
                    <td>
                        <input type="checkbox" v-model="data.Dstate">勾选表示启用，不勾选表示禁用
                    </td>
                </tr>
                <tr>
                    <td></td>
                    <td>
                        <input type="button" value="添加等级" @click="Dadd">
                    </td>
                </tr>
            </thead>
        </table>
    </div>
    <a href="/Dlist">等级显示列表</a> 
    <br>
    <a href="/Hlist">会员显示列表</a> 
</template>
<script setup lang="ts">
import { onMounted, ref } from 'vue';
import axios from 'axios';
import { useRouter } from 'vue-router';
//实例化
const router=useRouter();
const data=ref({
  "DId": 0,
  "Dname": "",
  "QuanYi": "",
  "QYwj": 0,
  "Dstate": true
});
const xlk=ref([  {
    "QYId": 0,
    "QYName": "",
    "QYState": ""
  }]);
onMounted(()=>{
    qyxlk();
})
const qyxlk=()=>{
    axios.get("https://localhost:7258/api/Deng/Qyxlk").then(res=>{
        xlk.value=res.data;
    })
}
const Dadd=()=>{
    if(data.value.Dname=="")
    {
        alert("等级名称不能为空");
        return;
    }
    if(data.value.QuanYi=="")
    {
        alert("等级权益不能为空");
        return;
    }
    if(data.value.QYwj==0)
    {
        alert("等级权益外键不能为空");
        return;
    }
    if(data.value.Dstate==null)
    {
        alert("等级权益不能为空");
        return;
    }
    axios.post("https://localhost:7258/api/Deng/AddDeng",data.value).then(res=>{
        if(res.data>0)
        {
            alert("等级添加成功");
            router.push({path:"/Dlist"})
        }
        else
        {
            alert("等级添加失败");
        }
    })
}


</script>

<style scoped>

</style>